package com.hgd.tools;

import org.hibernate.Session;

import com.hgd.ORM.ManagementStation;
import com.hgd.hibernate.HibernateUtil;

public class Delete {
	public int msDel(int msId) {
		Session session = HibernateUtil.getSesion();
		int flag = 0;
		try {
			session.beginTransaction();	
			String hql = "delete from Domain d where d.managementStation.MSId=?";
			flag = session.createQuery(hql) .setLong(0,msId)
																	   .executeUpdate();
			String hql2 = "update ManagementStation m set m.isInitialize=0 where m.MSId=?";
			flag = session.createQuery(hql2).setLong(0,msId).executeUpdate();
			session.flush();
			session.getTransaction().commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}finally{
			HibernateUtil.closeSession(session);
		}
		return flag;
	}
	public static void main(String[] args) {
		Delete delete = new Delete();
		delete.msDel(3);
	}
}
